package com.turing.post.transaction.impl;

import java.util.Date;
import java.util.List;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.turing.post.transaction.util.MchAddTradSummary;
import com.turing.post.transaction.util.MchAddTradSummaryDao;
import com.turing.post.util.GeneralDao;
import com.turing.post.util.PCPSApplicationException;

@Stateless(mappedName = "transaction.impl.MchAddTradSummaryDaoImpl")
@Remote
@Local
public class MchAddTradSummaryDaoImpl implements MchAddTradSummaryDao {
	/**
	 * 实体管理器
	 * 
	 * @see javax.persistence.EntityManager
	 */
	@PersistenceContext
	protected EntityManager _em;

	/**
	 * 插入
	 */
	public void insert(MchAddTradSummary mats) throws PCPSApplicationException {
		GeneralDao.insert(_em, mats);
	}

	/**
	 * 根据商户号、交易日期、交易流水号检索商户附加流水
	 * 
	 * @param merchantNo
	 * @param tranDate
	 * @param tranSeqNo
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<MchAddTradSummary> getAllMchAddTradSummaryByTranSeqNo(
			String merchantNo, Date tranDate, String tranSeqNo) {
		String sql = "select * from MchAddTradSummary where merchantNo = ?1 and tranDate = ?2 and tranSeqNo = ?3";
		Query query = _em.createNativeQuery(sql, MchAddTradSummary.class);
		query.setParameter(1, merchantNo);
		query.setParameter(2, tranDate);
		query.setParameter(3, tranSeqNo);
		List<MchAddTradSummary> matslist = query.getResultList();
		return matslist;
	}
}